package com.template.app.editor;

import java.util.LinkedHashSet;
import java.util.Set;

import org.springframework.util.StringUtils;

import com.template.app.service.GenericService;

public class SetEditor extends IdEditorSupport {

	public SetEditor(Class<?> clazz, GenericService service) {
		super(clazz, service);
	}
	
	@Override
	public void setAsText(String stringId) throws IllegalArgumentException {
		String[] ids = StringUtils.commaDelimitedListToStringArray(StringUtils.trimAllWhitespace(stringId));
		Set<Object> set = new LinkedHashSet<Object>();
		
		for (String id : ids) {
			set.add(getObject(id));
		}
		
		setValue(set);
	}
}
